package goover.unit06;

public class ThreadDemo03 {
    public static void main(String[] args){
        Test01 t1 = new Test01("t1");
        t1.start();
        for(int i = 0;i < 6;i++){
            System.out.println(Thread.currentThread().getName() + "-" +i);
            if(i == 3){
                System.out.print("线程让步：");
                Thread.yield();
            }
        }
    }
}
class Test01 extends Thread{
    public Test01(String name){
        super(name);
    }
    @Override
    public void run() {
        for(int i = 0;i < 8;i++){
            System.out.println(Thread.currentThread().getName() + "-" +i);
            if(i == 3){
                System.out.println("线程让步！");
                Thread.yield();
            }
            if(i == 5){
                try {
                    System.out.println("线程睡眠！");
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}